package mylab.base.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import mylab.annotation.rds.ColumnComment;
import mylab.annotation.rds.IsAutoIncrement;
import mylab.base.Identifiable;
import mylab.base.constants.DbConst;


@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public abstract class SnowflakeEntity extends Entity<String> {


    /**
     * 自动生成id【雪花算法】
     * MyBatis-Plus默认的主键策略是：ASSIGN_ID （使用了雪花算法）
     */
    @IsAutoIncrement
    @ColumnComment("唯一编码")
    @ApiModelProperty("唯一编码")
    @TableId(value = DbConst.COLUMN_ID, type = IdType.ASSIGN_ID)
    protected String id;

    @Override
    public int compareTo(Identifiable<String> o) {
        return id.compareTo(o.getId());
    }

}
